# -*- coding: utf-8 -*-

class Sites < Control
  
  def initialize()
    
    super("sites")
    @vw.list_delete_button = false
    
    @captions["name"] = $msg_sites_captions_name
    @captions["value"] = $msg_sites_captions_value
    
  end
  
  def add_page_values(values)
    
    values = self.page_default_settings(values)
    values["titlebar"] = "#{$msg_sites_edit_values} - #{values["title"]}"
    return values
    
  end
  
  def page_default_settings(values)
    
    #values["title"] = self.get_title()
    #values["page_description"] = self.get_page_description()
    #values["page_keywords"] = self.get_page_keywords()
    #values["css_file_name"] = self.get_css_file_name()
    #values["foot"] = self.get_foot()
    
    settings = @mdl.get_data()
    
    settings.each {|row|
      key = row["name"]
      val = row["value"]
      values[key] = val
    }
    
    values["titlebar"] = values["title"]
    
    #f = open($templete_dir + "header_option_edit.html")
    #f = File.open($templete_dir + "header_option_edit.html", :encoding => "UTF-8")
    f = File.open($templete_dir + "header_option_edit.html", "r")
    values["header_option"] = f.read
    f.close
    
    menu = Categorys.new()
    values["menu"] = menu.get_menu("items.rb")
    #values["menu"] = menu.get_menu_for_html()
    values["page_header_option"] = menu.get_header_option()
    
    item = Items.new()
    values["sidebar"] = item.get_sidebar()
    
    return values
    
  end
  
  def make_page_contents(mode, id)
    
    html  = "<div class='title'>#{$msg_sites_edit_values}</div>"
    html += super(mode, id)
    
    return html
    
  end
  
  def get_title()
    return CGI.escapeHTML(@mdl.get_field_by_status("value", "name='title'"))
  end
  
  def get_foot()
    return CGI.escapeHTML(@mdl.get_field_by_status("value", "name='foot'"))
  end
  
  def get_css_file_name()
    
    file = @mdl.get_field_by_status("value", "name='css_file_name'")
    if !File.exist?(file) then
      file = "default.css"
    end
    
    return CGI.escapeHTML(file)
  end
  
  def get_page_description()
    return CGI.escapeHTML(@mdl.get_field_by_status("value", "name='page_description'"))
  end
  
  def get_page_keywords()
    return CGI.escapeHTML(@mdl.get_field_by_status("value", "name='page_keywords'"))
  end
  
end
